package spring_mybatis_integration;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperFactoryBean;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
	public static void main(String[] args)	{
		ApplicationContext context = new ClassPathXmlApplicationContext("spring_mybatis_integration/spring_config.xml");
		CustomerService customerService = context.getBean("customerService", CustomerService.class);
		CustomerModel customerModel = customerService.getCustomerById(2);
		System.out.println(customerModel);


		try {
//			DefaultSqlSessionFactory defaultSqlSessionFactory = context.getBean("sqlSessionFactory", DefaultSqlSessionFactory.class);
//			SqlSession session = defaultSqlSessionFactory.openSession();
//			ICustomerDAO customerDAO = session.getMapper(ICustomerDAO.class);
//			CustomerModel customerModel = customerDAO.getCustomerById(1);
//			System.out.println(customerModel);
//			customerDAO.insert(new CustomerModel(2, "dong", 14));

		} catch (BeansException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
